<?php
/**
 * floor.php
 *
 * @copyright 2018 OpenCart.cn
 *
 * All Rights Reserved
 * @link http://guangdawangluo.com
 *
 * @author stiffer.chen <chenlin@opencart.cn>
 * @created 2018-07-15 01:38
 * @modified 2018-07-15 01:38
 */

class ControllerExtensionModuleFloor extends Controller
{
    public function index($setting)
    {
        //d($setting);
        $this->load->language('extension/module/floor');
        addScript('catalog/view/theme/default/javascript/swiper/js/swiper.js');
        addStyle('catalog/view/theme/default/javascript/swiper/css/swiper.min.css');
        $data['title'] = $setting['name'];
        $data['title_recommend'] = array();
        if ($setting['title_recommend']) {
            foreach ($setting['title_recommend'] as $recommend) {
                $data['title_recommend'][] = array(
                    'name' => $recommend['name'][$this->config->get('config_language_id')],
                    'href' => $recommend['href']
                );
            }
        }

        $data['products'] = array();
        if (isset($setting['products'])) {
            $this->load->model('catalog/product');
            foreach ($setting['products'] as $product_id) {
                $product = $this->model_catalog_product->getProduct($product_id);
                if ($product && $product['status']) {
                    $tmp_product = view_product($product);
                    $tmp_product['href'] = uriLink('product/product', 'product_id=' . $product['product_id']);
                    $data['products'][] = $tmp_product;
                }
            }
        }

        if ($data['products']) {
            $data['products'] = array_slice($data['products'], 0, 6);
        }

        $data['image'] = resizeImage($setting['image'], 400, 480);
        $data['image_recommends'] = array();
        if ($setting['image_recommend']) {
            foreach ($setting['image_recommend'] as $recommend) {
                $data['image_recommends'][] = array(
                    'name' => $recommend['name'][$this->config->get('config_language_id')],
                    'href' => $recommend['href']
                );
            }
        }

        $data['color'] = $setting['color'];
        $data['banners'] = array();
        if (isset($setting['banners'])) {
            foreach ($setting['banners'] as $banner) {
                $data['banners'][] = array(
                    'thumb' => resizeImage($banner['image'], 200, 480),
                    'href' => $banner['href'],
                    'title' => $banner['title'][$this->config->get('config_language_id')]
                );
            }
        }
        return $this->load->view('extension/module/floor', $data);
    }
}